package thread;

import org.junit.Test;

/**
 * @author liweimin
 * @date 2021/1/22 13:47
 * @description 实现Runnable接口，重写run()方法--->传递到Thread中，通过Thread对象调用start()
 * @since
 */
public class RunnableTest {
    public static class MyRunnable implements Runnable {
        @Override
        public void run() {
            System.out.println("this is myThread with implements Runnable");
        }
    }

    public static class IRunnable implements Runnable {

        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                if (i % 2 == 0) {
                    System.out.println(i + " IRunnable");
                }
            }
        }
    }

    @Test
    public void testRunnable() {
        new Thread(new MyRunnable()).start();
        new Thread(new IRunnable()).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("测试-匿名内部类");
            }
        }).start();
        new Thread(() -> {
            System.out.println("测试-函数式编程");
        }).start();
    }

    public static void main(String[] args) {
        new Thread(new MyRunnable()).start();
        //Java8-函数式编程
        new Thread(() -> {
            System.out.println("Java8-函数式编程");
        }).start();
    }
}
